//
//  SecondViewCell.m
//  UI - 豆瓣
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "SecondViewCell.h"
#import "UIImageView+WebCache.h"

@interface SecondViewCell()

@property(nonatomic, retain)UIImageView *headImageView;
@property(nonatomic, retain)UILabel *lable;



@end

@implementation SecondViewCell
- (void)dealloc
{
    [_headImageView release];
    [_lable release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubCell];
    }
    return self;
}

-(void)createSubCell{

    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 365, 118)];
    imageV.image = [UIImage imageNamed:@"bg_eventlistcell.png"];
    [self.contentView addSubview:imageV];
    [imageV release];
    
    
    self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 32, 80, 80)];
    [self.contentView addSubview:self.headImageView];
    self.headImageView.layer.masksToBounds = YES;

    self.headImageView.layer.cornerRadius = 40;
    
    self.headImageView.layer.borderWidth = 3;
    
    self.headImageView.layer.borderColor = [UIColor brownColor].CGColor;
    [self.headImageView release];
    
    
    
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(110, 50, 200, 40)];
    [self.contentView addSubview:self.lable];
    [self.lable release];
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(320, 50, 36, 36);
    [self.button setBackgroundImage:[UIImage imageNamed:@"star_unfav@2x.png"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
}

-(void)buttonAction: (UIButton *)button{

    if (self.movie.isGood == NO) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"star_faved@2x.png"] forState:UIControlStateNormal];
        
        [self.MyCellDelegate movieInfo:self.movie];
        
    }
    else{
    
        [button setBackgroundImage:[UIImage imageNamed:@"star_unfav@2x.png"] forState:UIControlStateNormal];
    }
    self.movie.isGood = !self.movie.isGood;
    
    
    
}


-(void)setMovie:(Movie *)movie{

    if (_movie != movie) {
        [_movie release];
        _movie = [movie retain];
    }
    self.lable.text = self.movie.movieName;
    NSURL *url = [NSURL URLWithString:self.movie.pic_url];
    [self.headImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"icon@2x.png"]];
    
    
    [self.button setBackgroundImage:[UIImage imageNamed:@"star_faved@2x.png"] forState:UIControlStateNormal];
    if (_movie.isGood == NO) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"star_unfav@2x.png"] forState:UIControlStateNormal];
        
    }
    
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
